<?php
/* 
Password securing function
uses hash() and double hashed salts placed in the end and in the middle of the password. It also adds username to hashed password for 
maximum security

// NOT YET IMPLEMENTED //

Credits: Jalil Benayachi 
Used documentation: phpmanual
*/
function randomString($lenght)
		{
		//Random string generator (for my home made captcha using canvas)
				//First, let's generate a random string
				$random = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $lenght);  //for Login in (short string)
				return $random;
		}

function saltandpepper($pwd, $salt, $pepper)
{
// First step, let's split the password in half so we can have some fun hiding the salt and the pepper
// To do so let's use str_split function. We get the lenght of the password using strlen and then move the split cursor 
// right after the middle character, so strlen/2 +1, we split. It generates an array of two values $password[0] and $password[1]
$password = str_split($pwd,(strlen($pwd)/2)+1); 
$tohash=$password[0].$salt.$password[1].$pepper;
return hash('md5', $tohash); 
}

